const mqtt = require('mqtt')

let username = "sailboat_mobile"
let password = "sailboat_mobile_2024"

let connectUrl = 'ws://180.107.109.102:8083/mqtt'

const clientId = `webstorm_${Math.floor(Math.random() * 10000) + 1}`

// 连接选项
const options = {
    clean: true, // true: 清除会话, false: 保留会话
    connectTimeout: 15000, // 超时时间
    clientId,
    username,
    password,
    keepalive: 5,
    will: {
        topic: `will-msg/${clientId}`,
        payload: 'offline',
        qos: 2,
        retain: false
    }
}

const client = mqtt.connect(connectUrl, options)

module.exports = {
    connectUrl,
    client
}
